package cn.ibizlab.odoo.core.odoo_survey.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Isurvey_label;
import cn.ibizlab.odoo.core.odoo_survey.domain.Survey_label;
import cn.ibizlab.odoo.core.odoo_survey.filter.Survey_labelSearchContext;
import cn.ibizlab.odoo.core.odoo_survey.service.ISurvey_labelService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[调查标签] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Survey_labelServiceImpl implements ISurvey_labelService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Isurvey_labelClientService survey_labelClientService;

    @Override
    public boolean create(Survey_label survey_label) {
        boolean bOk = false ;
        Isurvey_label clientModel = this.convert2Model(survey_label,null);
        survey_labelClientService.create(clientModel) ;
        this.convert2Domain(clientModel,survey_label);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void updateBatch(List<Survey_label> survey_labels, int batchSize) {

        //survey_labelClientService.updateBatch(survey_labels,batchSize) ;

    }

    @Override
    public boolean update(Survey_label survey_label) {
        boolean bOk = false ;
        Isurvey_label clientModel = this.convert2Model(survey_label,null);
        survey_labelClientService.update(clientModel) ;
        this.convert2Domain(clientModel,survey_label) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public void createBatch(List<Survey_label> survey_labels, int batchSize) {

                        //survey_labelClientService.createBatch(survey_labels,batchSize) ;

    }

    @Override
    public Survey_label get(Integer id) {
        Isurvey_label clientModel = survey_labelClientService.createModel();
        clientModel.setId(id);
        survey_labelClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Survey_label get(Survey_label survey_label) {
        Survey_label retsurvey_label = this.get(survey_label.getId()) ;
    	BeanCopier copier=BeanCopier.create(retsurvey_label.getClass(), survey_label.getClass(), false);
        copier.copy(retsurvey_label, survey_label, null);
        return survey_label ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //survey_labelClientService.removeBatch(survey_labels) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Isurvey_label clientModel = survey_labelClientService.createModel();
        clientModel.setId(id);
        survey_labelClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Survey_label> searchDefault(Survey_labelSearchContext context) {
        List<Survey_label> list = new ArrayList<Survey_label>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_label> clientModelList = survey_labelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_label clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_label>(list, context.getPageable(), clientModelList.getTotalElements());
    }


    /**
     * 根据用户查询
     */
    @Override
    public Page<Survey_label> selectByOdoo_create(Integer id){
        Survey_labelSearchContext context = new Survey_labelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_label> list = new ArrayList<Survey_label>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_label> clientModelList = survey_labelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_label clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_label>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据用户查询
     */
    @Override
    public Page<Survey_label> selectByOdoo_write(Integer id){
        Survey_labelSearchContext context = new Survey_labelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_label> list = new ArrayList<Survey_label>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_label> clientModelList = survey_labelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_label clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_label>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据调查问题查询
     */
    @Override
    public Page<Survey_label> selectByOdoo_question(Integer id){
        Survey_labelSearchContext context = new Survey_labelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_label> list = new ArrayList<Survey_label>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_label> clientModelList = survey_labelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_label clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_label>(list, context.getPageable(), clientModelList.getTotalElements());

    }

    /**
     * 根据调查问题查询
     */
    @Override
    public Page<Survey_label> selectByOdoo_question_id(Integer id){
        Survey_labelSearchContext context = new Survey_labelSearchContext();
        if(!org.springframework.util.StringUtils.isEmpty(id)){
            cn.ibizlab.odoo.util.SearchFieldFilter fieldFilter=new cn.ibizlab.odoo.util.SearchFieldFilter();
            fieldFilter.setParam("id");
            fieldFilter.setCondition(cn.ibizlab.odoo.util.enums.SearchFieldType.EQ);
            fieldFilter.setValue(id);
            context.getCondition().add(fieldFilter);
        }
        List<Survey_label> list = new ArrayList<Survey_label>();
        Page<cn.ibizlab.odoo.core.client.model.Isurvey_label> clientModelList = survey_labelClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Isurvey_label clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Survey_label>(list, context.getPageable(), clientModelList.getTotalElements());

    }



    public Isurvey_label convert2Model(Survey_label domain , Isurvey_label model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = survey_labelClientService.createModel() ;
        }

         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getWrite_dateDirtyFlag())
            model.setWrite_date(domain.getWrite_date());
         if(domain.getSequenceDirtyFlag())
            model.setSequence(domain.getSequence());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getQuizz_markDirtyFlag())
            model.setQuizz_mark(domain.getQuizz_mark());
         if(domain.getValueDirtyFlag())
            model.setValue(domain.getValue());
         if(domain.getCreate_dateDirtyFlag())
            model.setCreate_date(domain.getCreate_date());
         if(domain.getWrite_uid_textDirtyFlag())
            model.setWrite_uid_text(domain.getWrite_uid_text());
         if(domain.getCreate_uid_textDirtyFlag())
            model.setCreate_uid_text(domain.getCreate_uid_text());
         if(domain.getCreate_uidDirtyFlag())
            model.setCreate_uid(domain.getCreate_uid());
         if(domain.getQuestion_id_2DirtyFlag())
            model.setQuestion_id_2(domain.getQuestion_id_2());
         if(domain.getQuestion_idDirtyFlag())
            model.setQuestion_id(domain.getQuestion_id());
         if(domain.getWrite_uidDirtyFlag())
            model.setWrite_uid(domain.getWrite_uid());
        return model ;
    }

    public Survey_label convert2Domain( Isurvey_label model ,Survey_label domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Survey_label();
        }

        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getWrite_dateDirtyFlag())
            domain.setWrite_date(model.getWrite_date());
        if(model.getSequenceDirtyFlag())
            domain.setSequence(model.getSequence());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getQuizz_markDirtyFlag())
            domain.setQuizz_mark(model.getQuizz_mark());
        if(model.getValueDirtyFlag())
            domain.setValue(model.getValue());
        if(model.getCreate_dateDirtyFlag())
            domain.setCreate_date(model.getCreate_date());
        if(model.getWrite_uid_textDirtyFlag())
            domain.setWrite_uid_text(model.getWrite_uid_text());
        if(model.getCreate_uid_textDirtyFlag())
            domain.setCreate_uid_text(model.getCreate_uid_text());
        if(model.getCreate_uidDirtyFlag())
            domain.setCreate_uid(model.getCreate_uid());
        if(model.getQuestion_id_2DirtyFlag())
            domain.setQuestion_id_2(model.getQuestion_id_2());
        if(model.getQuestion_idDirtyFlag())
            domain.setQuestion_id(model.getQuestion_id());
        if(model.getWrite_uidDirtyFlag())
            domain.setWrite_uid(model.getWrite_uid());
        return domain ;
    }


}
